#include "HY1C_out.h"
﻿#include <stdio.h>
//#include <iostream>
#include "HY1L1bHeader.h"
#include "HY1L2Header.h"
#include "HY1L3Header.h"
#include <hdf5.h>
#include <zhdf.h>
#include <string.h>
#include "Process_L2B_OCT_SSC.h"
#include "math.h"
#include <malloc.h>
#define g_Scans  10
#define g_Sample 10
int Geo_size_Line;
int Geo_size_Sample;

int iRank;
hsize_t hTwoDims[2];

//读取数据集信息
int istatus;
int iOverWrite = 0;
struct HY1_L1B_FILE_INFO L1BHeadinfor;

char pstrIPhyName[512];
char pstrOPhyName[512];
char Description[512];

int HY1_OCT_UVI_L2B_SSC(struct Name_List *namelist)
{
	//进行结构体解析
	//strcpy(pstrIPhyName,namelist->pstrIPhyName.c_str());
	//strcpy(pstrOPhyName,namelist->pstrOPhyName.c_str());
	strcpy(pstrIPhyName, namelist->pstrIPhyName);
	strcpy(pstrOPhyName, namelist->pstrOPhyName);
	//HY1C_out("\n开始进行COCTS悬浮泥沙算法悬浮泥沙反演模块\n");
	//HY1C_out("\n第一步：进行L1B数据属性信息读取\n");
	
	//读取数据属性信息
	int istatus;
	struct HY1_L2_OCT_UVI_FILE_INFO pstructHY1L2OCTUVIFileInfo;
	istatus = ZHDFReadHY1L2OctUviFileInfo(pstrIPhyName,&pstructHY1L2OCTUVIFileInfo);
	if(istatus != 0)
	{
		//HY1C_out("L1B 数据属性信息读取错误!\n");
		namelist->Description = "L1B 数据属性信息读取错误!";
		return 1;
	}
	
	//HY1C_out("\n第二步：创建输出结果文件\n");
	//HY1C_out("-输入输出文件名（不含文件路径）\n");
	char InputFileName[256] = {0};
	int i=0;
	for(i = 0 ; i < strlen(pstrIPhyName) ; i++)
	{
		if(pstrIPhyName[strlen(pstrIPhyName) - i - 1] == '/')
		{
			memcpy(InputFileName,pstrIPhyName+strlen(pstrIPhyName) - i , i);
			break;
		}
	}
	char OutFileName[256] = {0};
        
	for(i = 0 ; i < strlen(pstrOPhyName) ; i++)
	{
		if(pstrOPhyName[strlen(pstrOPhyName) - i - 1] == '/')
		{
			memcpy(OutFileName,pstrOPhyName+strlen(pstrOPhyName) - i , i);
			break;
		}
	}	

	memcpy(pstructHY1L2OCTUVIFileInfo.sProductName,OutFileName,256);  
	memcpy(pstructHY1L2OCTUVIFileInfo.sInputFile,InputFileName,256);  
	//HY1C_out("-L2B属性信息添加到文件中\n");
	istatus = ZHDFWriteHY1L2OCTUVIFileInfo(pstrOPhyName,&pstructHY1L2OCTUVIFileInfo,1);

	//属性信息集成L1A数据属性信息
	//strcpy(L2AOCTUVIHeadinfor.sCalFile,L1BHeadinfor.sCalFile);	
	//HY1C_out("\n第三步：创建Group组\n");	
	int iOverWrite = 0;
	char *a[] = {"Sensor Band Parameters","Scan-Line Attributes","Navigation Data","Geophysical Data"};  
	char **band = a;  
	ZHDFCreateGroup(pstrOPhyName, band, 4 ,iOverWrite);
	
	//HY1C_out("\n第四步：数据处理\n");
	//HY1C_out("-获取数据大小，用于动态申请内存\n");
/* 	hsize_t hDims[2];
	istatus = ZHDFGetDataSize(pstrIPhyName, "/Navigation Data/Latitude", hDims);
	if(istatus !=0)
	{
		//HY1C_out("ZHDFGetDataSize failed!\n");
		namelist->Description = "ZHDFGetDataSize failed!";
		return 1;	
	}
	Geo_size_Line = hDims[0];
	Geo_size_Sample = hDims[1]; */
	Geo_size_Line = pstructHY1L2OCTUVIFileInfo.iNumberOfScanLines;
	Geo_size_Sample = pstructHY1L2OCTUVIFileInfo.iPixelsPerScanLine;
	

	istatus = Geophysical_Data_OCTUVI(pstrIPhyName, pstrOPhyName);
	if(istatus != 0)
	{
		//HY1C_out("Geophysical_Data_OCTUVI failed!\n");
		namelist->Description = "Geophysical_Data_OCTUVI failed!";
		return istatus;
	}
	
	//HY1C_out("\n第五步：剩余Group数据进行继承\n");
	//HY1C_out("-Sensor_Band_Parameters信息\n");	
	istatus = Sensor_Band_Parameters(pstrIPhyName,pstrOPhyName);
	if(istatus != 0)
	{
		//HY1C_out("Sensor_Band_Parameters failed!\n");
		namelist->Description = "Sensor_Band_Parameters failed!";
		return istatus;
	}
	
	//HY1C_out("-Scan_Line_Attributes信息\n");
	istatus = Scan_Line_Attributes(pstrIPhyName, pstrOPhyName);
	if(istatus != 0)
	{
		//HY1C_out("Scan_Line_Attributes failed!\n");
		namelist->Description = "Scan_Line_Attributes failed!";
		return istatus;
	}
	
	//HY1C_out("-Navigation_Data信息\n");
	istatus = Navigation_Data(pstrIPhyName, pstrOPhyName);
	if(istatus != 0)
	{
		//HY1C_out("Navigation_Data failed!\n");
		namelist->Description = "Navigation_Data failed!";
		return istatus;
	}

	//HY1C_out("\n程序正常结束，完成！\n");
	namelist->Description = "程序正常结束，完成!";
	return 0;
}

int Sensor_Band_Parameters(char *pstrIPhyName,char *pstrOPhyName)
{
	//写Group组Sensor Band Parameters数据   2018-6-7 12:17:46
	iRank = 1;
	int g_Wavelength = 4;  //12或者14   2018-6-7 13:47:19
	int Sensor_size = 4;
	hTwoDims[0] = g_Wavelength;
	hTwoDims[1] = 1;
	
	//波长
	int *Wavelength= (int *) malloc(g_Wavelength * sizeof(int));
	
	struct HY1_SDS_Sensor_INFO struct_Sensor_INFO;
	istatus = ZHDFReadSDSDataInt(pstrIPhyName,"/Sensor Band Parameters/Wavelength",Wavelength, &struct_Sensor_INFO);
	
	istatus = ZHDFWriteSDSDataInt(pstrOPhyName,"/Sensor Band Parameters/Wavelength", iRank, hTwoDims,  \
								Wavelength, &struct_Sensor_INFO,iOverWrite);
	//"系统定标"线性系数							
	hTwoDims[0] = Sensor_size;
	hTwoDims[1] = 1;
	float *Syscal_Gain  = (float *) malloc(Sensor_size * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Sensor Band Parameters/Syscal Gain",Syscal_Gain, &struct_Sensor_INFO);

	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Sensor Band Parameters/Syscal Gain", iRank, hTwoDims,  \
								Syscal_Gain, &struct_Sensor_INFO,iOverWrite);
	//"系统定标"系数偏移
	float *Syscal_Offset = (float *) malloc(Sensor_size * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Sensor Band Parameters/Syscal Offset",Syscal_Offset, &struct_Sensor_INFO);
	
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Sensor Band Parameters/Syscal Offset", iRank, hTwoDims,  \
								Syscal_Offset, &struct_Sensor_INFO,iOverWrite);
	//平均大气层外太阳辐照度
	float *F0 = (float *) malloc(Sensor_size * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Sensor Band Parameters/F0",F0, &struct_Sensor_INFO);
	
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Sensor Band Parameters/F0", iRank, hTwoDims,  \
								F0, &struct_Sensor_INFO,iOverWrite);
	
	//波段等效臭氧吸收系数
	strcpy(struct_Sensor_INFO.strUnit, "1/cm");
	float *k_oz = (float *) malloc(Sensor_size * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Sensor Band Parameters/k_oz",k_oz, &struct_Sensor_INFO);
	
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Sensor Band Parameters/k_oz", iRank, hTwoDims,  \
								k_oz, &struct_Sensor_INFO,iOverWrite);
								
	//波段等效瑞利光学厚度
	float *tau_r = (float *) malloc(Sensor_size * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Sensor Band Parameters/tau_r",tau_r, &struct_Sensor_INFO);
	
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Sensor Band Parameters/tau_r", iRank, hTwoDims,  \
								tau_r,&struct_Sensor_INFO,iOverWrite);
	
	if(Wavelength != NULL)
	{
		free (Wavelength);//Wavelength=NULL;
	}
	if(Syscal_Gain != NULL)
	{
		free(Syscal_Gain);//Syscal_Gain=NULL;
	}
	if(Syscal_Offset != NULL)
	{
		free(Syscal_Offset);//Syscal_Offset=NULL;
	}
	if(Syscal_Offset != NULL)
	{
		free(F0);//F0=NULL;
	}
	if(Syscal_Offset != NULL)
	{
		free(k_oz);//k_oz=NULL;
	}
	if(Syscal_Offset != NULL)
	{
		free(tau_r);//tau_r=NULL;
	}
	return 0;
}

int Scan_Line_Attributes(char *pstrIPhyName, char *pstrOPhyName)
{
	//写Group组Scan-Line Attributes数据   2018-6-7 12:17:46
	iRank = 1;
	hTwoDims[0] = 1;
	hTwoDims[1] = 1;
	struct HY1_SDS_INFO struct_SDS_INFO;
	//扫描年份
	int Year;
	istatus = ZHDFReadSDSDataInt(pstrIPhyName,"/Scan-Line Attributes/Year",&Year, &struct_SDS_INFO);
	
	istatus = ZHDFWriteSDSDataInt(pstrOPhyName,"/Scan-Line Attributes/Year", iRank, hTwoDims,  \
								&Year, &struct_SDS_INFO,  iOverWrite);		
	//扫描儒略日
	int Day;
	istatus = ZHDFReadSDSDataInt(pstrIPhyName,"/Scan-Line Attributes/Day",&Day, &struct_SDS_INFO);
	
	istatus = ZHDFWriteSDSDataInt(pstrOPhyName,"/Scan-Line Attributes/Day", iRank, hTwoDims,  \
								&Day, &struct_SDS_INFO, iOverWrite);		
	//扫描行时间
	int Millisecond;
	istatus = ZHDFReadSDSDataInt(pstrIPhyName,"/Scan-Line Attributes/Millisecond",&Millisecond, &struct_SDS_INFO);
	
	istatus = ZHDFWriteSDSDataInt(pstrOPhyName,"/Scan-Line Attributes/Millisecond", iRank, hTwoDims,  \
								&Millisecond,&struct_SDS_INFO, iOverWrite);		
	//扫描行起始像元纬度
	hTwoDims[0] = Geo_size_Line;
	hTwoDims[1] = Geo_size_Sample;
	float *Start_Latitude = (float *) malloc(Geo_size_Line * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Scan-Line Attributes/Start Latitude",Start_Latitude,&struct_SDS_INFO);
	if(istatus !=0)
	{
		char strTmp[200] = {0};
		memset(strTmp,0,sizeof(strTmp));
		sprintf(strTmp,"Read  %s fail!\n",pstrIPhyName);		
		//HY1C_out("%s\n",strTmp);
		return 1;	  
  	}

	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Scan-Line Attributes/Start Latitude", iRank, hTwoDims,  \
								Start_Latitude, &struct_SDS_INFO,  iOverWrite);
	//扫描行起始像元经度
	float *Start_Longitude = (float *) malloc(Geo_size_Line * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Scan-Line Attributes/Start Longitude",Start_Longitude,&struct_SDS_INFO);
	if(istatus !=0)
	{
		char strTmp[200] = {0};
		memset(strTmp,0,sizeof(strTmp));
		sprintf(strTmp,"Read  %s fail!\n",pstrIPhyName);		
		//HY1C_out("%s\n",strTmp);
		return 1;	  
  	}
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Scan-Line Attributes/Start Longitude", iRank, hTwoDims,  \
								Start_Longitude, &struct_SDS_INFO,  iOverWrite);
	//扫描行中心像元纬度
	float *Center_Latitude = (float *) malloc(Geo_size_Line * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Scan-Line Attributes/Center Latitude",Center_Latitude,&struct_SDS_INFO);
	if(istatus !=0)
	{
		char strTmp[200] = {0};
		memset(strTmp,0,sizeof(strTmp));
		sprintf(strTmp,"Read  %s fail!\n",pstrIPhyName);		
		//HY1C_out("%s\n",strTmp);
		return 1;	  
  	}
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Scan-Line Attributes/Center Latitude", iRank, hTwoDims,  \
								Center_Latitude, &struct_SDS_INFO, iOverWrite);
								
	//扫描行中心像元经度
	float *Center_Longitude = (float *) malloc(Geo_size_Line * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Scan-Line Attributes/Center Longitude",Center_Longitude,&struct_SDS_INFO);
	if(istatus !=0)
	{
		char strTmp[200] = {0};
		memset(strTmp,0,sizeof(strTmp));
		sprintf(strTmp,"Read  %s fail!\n",pstrIPhyName);		
		//HY1C_out("%s\n",strTmp);
		return 1;	  
  	}
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Scan-Line Attributes/Center Longitude", iRank, hTwoDims,  \
								Center_Longitude, &struct_SDS_INFO,  iOverWrite);
								
	//扫描行结束像元纬度
	float *End_Latitude = (float *) malloc(Geo_size_Line * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Scan-Line Attributes/End Latitude",End_Latitude,&struct_SDS_INFO);
	if(istatus !=0)
	{
		char strTmp[200] = {0};
		memset(strTmp,0,sizeof(strTmp));
		sprintf(strTmp,"Read  %s fail!\n",pstrIPhyName);		
		//HY1C_out("%s\n",strTmp);
		return 1;	  
  	}
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Scan-Line Attributes/End Latitude", iRank, hTwoDims,  \
								End_Latitude,&struct_SDS_INFO,  iOverWrite);
								
	//扫描行结束像元经度
	float *End_Longitude = (float *) malloc(Geo_size_Line * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Scan-Line Attributes/End Longitude",End_Longitude,&struct_SDS_INFO);
	if(istatus !=0)
	{
		char strTmp[200] = {0};
		memset(strTmp,0,sizeof(strTmp));
		sprintf(strTmp,"Read  %s fail!\n",pstrIPhyName);		
		//HY1C_out("%s\n",strTmp);
		return 1;	  
  	}
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Scan-Line Attributes/End Longitude", iRank, hTwoDims,  \
								End_Longitude,&struct_SDS_INFO,  iOverWrite);
	//扫描行中心像元太阳天顶角
	float *Center_Solar_Zenith_Angle = (float *) malloc(Geo_size_Line * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Scan-Line Attributes/Center Solar Zenith Angle",Center_Solar_Zenith_Angle,&struct_SDS_INFO);
	if(istatus !=0)
	{
		char strTmp[200] = {0};
		memset(strTmp,0,sizeof(strTmp));
		sprintf(strTmp,"Read  %s fail!\n",pstrIPhyName);		
		//HY1C_out("%s\n",strTmp);
		return 1;	  
  	}
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Scan-Line Attributes/Center Solar Zenith Angle", iRank, hTwoDims,  \
								Center_Solar_Zenith_Angle, &struct_SDS_INFO, iOverWrite);
	free(Start_Latitude);//Start_Latitude=NULL;
	free(Start_Longitude);//Start_Longitude=NULL;
	free(Center_Latitude);//Center_Latitude=NULL;
	free(Center_Longitude);//Center_Longitude=NULL;
	free(End_Latitude);//End_Latitude=NULL;
	free(End_Longitude);//End_Longitude=NULL;
	free(Center_Solar_Zenith_Angle);//Center_Solar_Zenith_Angle=NULL;	
	
	return 0;
}

int Navigation_Data(char *pstrIPhyName, char *pstrOPhyName)
{
	//写Group组Navigation Data数据   2018-6-7 12:17:46
	iRank = 2;
	hTwoDims[0] = Geo_size_Line;
	hTwoDims[1] = Geo_size_Sample;
	struct HY1_SDS_INFO struct_SDS_INFO;
	
	float *Latitude = (float *) malloc(Geo_size_Line*Geo_size_Sample * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Navigation Data/Latitude",Latitude,&struct_SDS_INFO);
	if(istatus !=0)
	{
		char strTmp[200] = {0};
		memset(strTmp,0,sizeof(strTmp));
		sprintf(strTmp,"Read  %s fail!\n",pstrIPhyName);		
		//HY1C_out("%s\n",strTmp);
		return 1;	  
  	}

	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Navigation Data/Latitude", iRank, hTwoDims,  \
								Latitude, &struct_SDS_INFO, iOverWrite);
	
	//图象各像元经度
	float *Longitude = (float *) malloc(Geo_size_Line*Geo_size_Sample * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Navigation Data/Longitude",Longitude,&struct_SDS_INFO);
	if(istatus !=0)
	{
		char strTmp[200] = {0};
		memset(strTmp,0,sizeof(strTmp));
		sprintf(strTmp,"Read  %s fail!\n",pstrIPhyName);		
		//HY1C_out("%s\n",strTmp);
		return 1;	  
  	}
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Navigation Data/Longitude", iRank, hTwoDims,  \
								Longitude, &struct_SDS_INFO, iOverWrite);
	
	//每行定位像元数
	iRank = 1;
	hTwoDims[0] = 1;
	hTwoDims[1] = 1;
	int Navigation_Points = 0;
	istatus = ZHDFReadSDSDataInt(pstrIPhyName,"/Navigation Data/First Navigation Point", &Navigation_Points,&struct_SDS_INFO);
	
	istatus = ZHDFWriteSDSDataInt(pstrOPhyName,"/Navigation Data/Navigation Points", iRank, hTwoDims,  \
								&Navigation_Points, &struct_SDS_INFO, iOverWrite);								
	
	//每行起始定位像元号
	int First_Navigation_Point=0;
	istatus = ZHDFReadSDSDataInt(pstrIPhyName,"/Navigation Data/First Navigation Point", &First_Navigation_Point,&struct_SDS_INFO);
	
	strcpy(struct_SDS_INFO.strDataDescription,"Initial positioning pixel number for each row");
	istatus = ZHDFWriteSDSDataInt(pstrOPhyName,"/Navigation Data/First Navigation Point", iRank, hTwoDims,  \
								&First_Navigation_Point, &struct_SDS_INFO, iOverWrite);	
	//每行定位间隔像元数
	int Pixel_intervals_Navigation_Points;
	istatus = ZHDFReadSDSDataInt(pstrIPhyName,"/Navigation Data/Pixel-intervals of Navigation Points", &Pixel_intervals_Navigation_Points,&struct_SDS_INFO);								
	
	istatus = ZHDFWriteSDSDataInt(pstrOPhyName,"/Navigation Data/Pixel-intervals of Navigation Points", iRank, hTwoDims,  \
								&Pixel_intervals_Navigation_Points, &struct_SDS_INFO, iOverWrite);		
	
	return 0;
}

//COCTS悬浮泥沙算法   算法示例  2018-7-25 17:13:20
int Geophysical_Data_OCTUVI(char *pstrIPhyName, char *pstrOPhyName)
{
	//2018-7-25 16:56:30
	iRank = 2;
	hTwoDims[0] = Geo_size_Line;
	hTwoDims[1] = Geo_size_Sample;
	
	//HY1C_out("-读取490nm波段归一化离水辐亮度\n");
	//读取数据集信息 490nm波段归一化离水辐亮度
	float *DN_1_490nm = (float *) malloc(Geo_size_Line*Geo_size_Sample * sizeof(float));
	struct HY1_SDS_Geophysical_INFO struct_Geophysical_INFO;
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Geophysical Data/nLw490",DN_1_490nm,&struct_Geophysical_INFO);
	
	//HY1C_out("-读取750nm波段归一化离水辐亮度\n");
	//读取数据集信息 750nm波段归一化离水辐亮度
	float *DN_1_750nm = (float *) malloc(Geo_size_Line*Geo_size_Sample * sizeof(float));
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Geophysical Data/nLw750",DN_1_750nm,&struct_Geophysical_INFO);
	
	//HY1C_out("-读取平均大气层外太阳辐照度\n");
	//读取平均大气层外太阳辐照度
	int Sensor_size = 12;
	//float F0[Sensor_size];
	float *F0 = (float *) malloc(Sensor_size*sizeof(float));
	struct HY1_SDS_Sensor_INFO struct_Sensor_INFO;
	istatus = ZHDFReadSDSDataFloat(pstrIPhyName,"/Sensor Band Parameters/F0",F0, &struct_Sensor_INFO);
	//对F0进行处理，由于全部为0
	int i;
	for(i=0;i<Sensor_size;i++)
	{
		F0[i] = 1.0;
	}
	
	//HY1C_out("-程序计算过程\n");
	float *SSC= (float *) malloc(Geo_size_Line*Geo_size_Sample * sizeof(float));
	float Ratio,a_490nm,b_750nm;
	/*****程序计算过程********/
	for(i=0;i<Geo_size_Line*Geo_size_Sample;i++)
	{
		a_490nm = DN_1_490nm[i]/F0[4];
		b_750nm = DN_1_750nm[i]/F0[7];
		if(a_490nm != 0)
		{
			Ratio = b_750nm/a_490nm;
		}
		else
		{
			Ratio = 1;
		}	
		
		SSC[i] = pow(10,(1.0785+1.123*Ratio));
	}
	
	//HY1C_out("-将SSC结果数据输出到HDF文件中\n");
	strcpy(struct_Geophysical_INFO.strDataDescription, "ssc");
	strcpy(struct_Geophysical_INFO.strUnit, "mg/L");
	strcpy(struct_Geophysical_INFO.strType, "float32");
	struct_Geophysical_INFO.fSlope = 1.0;
	struct_Geophysical_INFO.fOffset = 0.0;
	istatus = ZHDFWriteSDSDataFloat(pstrOPhyName,"/Geophysical Data/SSC", iRank, hTwoDims,  \
								SSC, &struct_Geophysical_INFO,iOverWrite);
	
	free(SSC);//SSC=NULL;
	free(DN_1_490nm);//DN_1_490nm=NULL;
	free(DN_1_750nm);//DN_1_750nm=NULL;
	free(F0);// F0 = NULL;
	return 0;
}
